package com.ruoyi.job.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.job.domain.EtlTaskState;
import com.ruoyi.job.service.IEtlTaskStateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 任务执行状态表Controller
 * 
 * @author ruoyi
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/taskState")
public class EtlTaskStateController extends BaseController
{
    @Autowired
    private IEtlTaskStateService etlTaskStateService;

    /**
     * 查询任务执行状态表列表
     */
    @PreAuthorize(hasPermi = "job:taskState:list")
    @GetMapping("/list")
    public TableDataInfo list(EtlTaskState etlTaskState)
    {
        startPage();
        List<EtlTaskState> list = etlTaskStateService.selectEtlTaskStateList(etlTaskState);
        return getDataTable(list);
    }

    /**
     * 导出任务执行状态表列表
     */
    @PreAuthorize(hasPermi = "job:taskState:export")
    @Log(title = "任务执行状态表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EtlTaskState etlTaskState) throws IOException
    {
        List<EtlTaskState> list = etlTaskStateService.selectEtlTaskStateList(etlTaskState);
        ExcelUtil<EtlTaskState> util = new ExcelUtil<EtlTaskState>(EtlTaskState.class);
        util.exportExcel(response, list, "任务执行状态表数据");
    }

    /**
     * 获取任务执行状态表详细信息
     */
    @PreAuthorize(hasPermi = "job:taskState:query")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") String taskId)
    {
        return AjaxResult.success(etlTaskStateService.selectEtlTaskStateById(taskId));
    }

    /**
     * 新增任务执行状态表
     */
    @PreAuthorize(hasPermi = "job:taskState:add")
    @Log(title = "任务执行状态表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EtlTaskState etlTaskState)
    {
        return toAjax(etlTaskStateService.insertEtlTaskState(etlTaskState));
    }

    /**
     * 修改任务执行状态表
     */
    @PreAuthorize(hasPermi = "job:taskState:edit")
    @Log(title = "任务执行状态表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EtlTaskState etlTaskState)
    {
        return toAjax(etlTaskStateService.updateEtlTaskState(etlTaskState));
    }

    /**
     * 删除任务执行状态表
     */
    @PreAuthorize(hasPermi = "job:taskState:remove")
    @Log(title = "任务执行状态表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable String[] taskIds)
    {
        return toAjax(etlTaskStateService.deleteEtlTaskStateByIds(taskIds));
    }
}
